using System;
using System.Collections;
using UnityEngine;

[ExecuteInEditMode]
public class ActivityIndicator : MonoBehaviour
{
	public static bool activEnabled;

	public static ActivityIndicator thisScript;

	public Texture2D texture;

	public float angle;

	private Vector2 size = new Vector2(100f, 100f);

	private Vector2 pos = new Vector2(0f, 0f);

	private Rect rect;

	private Vector2 pivot;

	private float rotSpeed = 180f;

	public static bool canClear = true;

	private void Awake()
	{
	}

	private void Start()
	{
		thisScript = this;
		UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
		size *= (float)Screen.width / 768f;
		UpdateSettings();
		Invoke("UpdateSettings", 0.5f);
	}

	private void OnDestroy()
	{
	}

	private void UpdateSettings()
	{
		pos = new Vector2(size.x, (float)Screen.height - size.y * 1.5f);
		rect = new Rect(pos.x - size.x * 0.5f, pos.y - size.y * 0.5f, size.x, size.y);
		pivot = new Vector2(rect.xMin + rect.width * 0.5f, rect.yMin + rect.height * 0.5f);
	}

	private void OnGUI()
	{
		if (activEnabled)
		{
			GUI.depth = 0;
			angle = rotSpeed * Time.realtimeSinceStartup;
			angle = (int)angle % 360;
			Matrix4x4 matrix = GUI.matrix;
			GUIUtility.RotateAroundPivot(angle, pivot);
			GUI.DrawTexture(rect, texture);
			GUI.matrix = matrix;
		}
	}

	public void iOSMemoryWarningReceiver()
	{
		StartCoroutine(UnloadRes());
	}

	private IEnumerator UnloadRes()
	{
		if (canClear)
		{
			canClear = false;
			GC.Collect();
			yield return new WaitForSeconds(0.1f);
			AsyncOperation unload = Resources.UnloadUnusedAssets();
			while (!unload.isDone)
			{
				yield return null;
			}
			canClear = true;
			if (BCWDebug.isDebugBuild)
			{
				BCWDebug.LogWarning("iOSMemoryWarningReceiver");
			}
		}
	}

	private void IncludeCleareMemory()
	{
		canClear = true;
	}
}
